package com.ecube.sql;

import com.ecube.mqtt.MqttUtils;
import com.ecube.mqtt.mysql.Query;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class State1 {

    public static void main(String[] args) throws InterruptedException {
        int dcMeterElectAdd =34;
        int dcMeterElect = 0;

        while (true) {
            sendRealDataMQTT("UAT", "999099", dcMeterElect);
            dcMeterElect = dcMeterElectAdd + dcMeterElect;
            Thread.sleep(1000*60);
        }
    }
    public static void sendRealDataMQTT(String env, String externalCode, int dcMeterElect) {
        String pubTopic = Query.getProductCode(env, externalCode) + externalCode + "/S2M/state";
        String version = Query.getVersion(env,externalCode);
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //仓位实时状态
        String content = " {\n" +
                "    \"header\": {\n" +
                "        \"version\": \"V3.0.7\",\n" +
                "        \"timeStamp\": \"" + dateFormat.format(date) + "\",\n" +
                "        \"reason\": 2,\n" +
                "        \"index\": 2939,\n" +
                "        \"function\": \"cabinetState\"\n" +
                "    },\n" +
                "    \"dataBody\": [\n" +
                "        {\n" +
                "            \"swapSelectedCabinet\": -1,\n" +
                "            \"soh\": 100,\n" +
                "            \"soc\": 100,\n" +
                "            \"ratedElect\": 284.3,\n" +
                "            \"chgState\": 1,\n" +
                "            \"cabinetType\": 1,\n" +
                "            \"cabinetNo\": 1,\n" +
                "            \"batType\": 1,\n" +
                "            \"batState\": 3,\n" +
                "            \"batID\": \"999BBDADA007\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"swapSelectedCabinet\": -1,\n" +
                "            \"soh\": 100,\n" +
                "            \"soc\": 99.7,\n" +
                "            \"ratedElect\": 284.3,\n" +
                "            \"chgState\": 1,\n" +
                "            \"cabinetType\": 1,\n" +
                "            \"cabinetNo\": 2,\n" +
                "            \"batType\": 1,\n" +
                "            \"batState\": 1,\n" +
                "            \"batID\": \"888BBD9KA005\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"swapSelectedCabinet\": -1,\n" +
                "            \"soh\": 95.60000000000001,\n" +
                "            \"soc\": 100,\n" +
                "            \"ratedElect\": 0,\n" +
                "            \"chgState\": 1,\n" +
                "            \"cabinetType\": 1,\n" +
                "            \"cabinetNo\": 3,\n" +
                "            \"batType\": -1,\n" +
                "            \"batState\": 2,\n" +
                "            \"batID\": \"777370340293\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"swapSelectedCabinet\": -1,\n" +
                "            \"soh\": 94,\n" +
                "            \"soc\": 100,\n" +
                "            \"ratedElect\": 0,\n" +
                "            \"chgState\": 1,\n" +
                "            \"cabinetType\": 1,\n" +
                "            \"cabinetNo\": 4,\n" +
                "            \"batType\": -1,\n" +
                "            \"batState\": 1,\n" +
                "            \"batID\": \"666455340283\"\n" +
                "        }\n" +
                "    ]\n" +
                "}";

        //充电机实时状态
        String content1 = " {\n" +
                "    \"header\": {\n" +
                "        \"version\": \"V3.0.7\",\n" +
                "        \"timeStamp\": \"" + dateFormat.format(date) + "\",\n" +
                "        \"reason\": 1,\n" +
                "        \"index\": 130,\n" +
                "        \"function\": \"chargerState\"\n" +
                "    },\n" +
                "    \"dataBody\": [\n" +
                "        {\n" +
                "            \"workMode\": 1,\n" +
                "            \"startType\": 1,\n" +
                "            \"soc\": 100,\n" +
                "            \"smokeAlarm\": 1,\n" +
                "            \"plugSameBat\": 1,\n" +
                "            \"moduleState\": \"2,2,2,2,2,2,2,2,2,2\",\n" +
                "            \"moduleNum\": 10,\n" +
                "            \"gunNum\": 2,\n" +
                "            \"gunList\": [\n" +
                "                {\n" +
                "                    \"workMode\": 1,\n" +
                "                    \"stopReason\": 50,\n" +
                "                    \"soc\": 100,\n" +
                "                    \"plugTemp\": \"24,25\",\n" +
                "                    \"limitVal\": 400,\n" +
                "                    \"gunOutCont\": \"1,1\",\n" +
                "                    \"gunNo\": 1,\n" +
                "                    \"fuseAlarm\": 1,\n" +
                "                    \"elecLock\": 0,\n" +
                "                    \"dcMeterElect\": 4480.35,\n" +
                "                    \"currLimit\": 2,\n" +
                "                    \"connOutCont\": \"1,1\",\n" +
                "                    \"chgState\": 3,\n" +
                "                    \"batID\": \"999BBDADA007\",\n" +
                "                    \"batFault\": \"-\",\n" +
                "                    \"batConn\": 1,\n" +
                "                    \"auxPowerVolt\": 2,\n" +
                "                    \"auxPowerState\": 1\n" +
                "                },\n" +
                "                {\n" +
                "                    \"workMode\": 1,\n" +
                "                    \"stopReason\": 0,\n" +
                "                    \"soc\": 100,\n" +
                "                    \"plugTemp\": \"25,25\",\n" +
                "                    \"limitVal\": 0,\n" +
                "                    \"gunOutCont\": \"1,1\",\n" +
                "                    \"gunNo\": 2,\n" +
                "                    \"fuseAlarm\": 1,\n" +
                "                    \"elecLock\": 0,\n" +
                "                    \"dcMeterElect\": 4462.09,\n" +
                "                    \"currLimit\": 1,\n" +
                "                    \"connOutCont\": \"1,1\",\n" +
                "                    \"chgState\": 2,\n" +
                "                    \"batID\": \"999BBDADA007\",\n" +
                "                    \"batFault\": \"-\",\n" +
                "                    \"batConn\": 1,\n" +
                "                    \"auxPowerVolt\": 2,\n" +
                "                    \"auxPowerState\": 1\n" +
                "                }\n" +
                "            ],\n" +
                "            \"emergStop\": 1,\n" +
                "            \"door\": 1,\n" +
                "            \"comm\": 1,\n" +
                "            \"chgSwitch\": 1,\n" +
                "            \"chgState\": 2,\n" +
                "            \"chgRunMode\": 1,\n" +
                "            \"chgID\": \"9990990001000001\",\n" +
                "            \"chgFault\": \"-\",\n" +
                "            \"cabinetNo\": 1,\n" +
                "            \"batState\": 1,\n" +
                "            \"batID\": \"999BBDADA007\",\n" +
                "            \"batFault\": \"-\",\n" +
                "            \"batConn\": 1,\n" +
                "            \"acCont\": 2\n" +
                "        },\n" +
                "        {\n" +
                "            \"workMode\": 1,\n" +
                "            \"startType\": 1,\n" +
                "            \"soc\": 89.7,\n" +
                "            \"smokeAlarm\": 1,\n" +
                "            \"plugSameBat\": 2,\n" +
                "            \"moduleState\": \"2,2,2,2,2,2,2,2,2,2\",\n" +
                "            \"moduleNum\": 10,\n" +
                "            \"gunNum\": 2,\n" +
                "            \"gunList\": [\n" +
                "                {\n" +
                "                    \"workMode\": 1,\n" +
                "                    \"stopReason\": 52,\n" +
                "                    \"soc\": 100,\n" +
                "                    \"plugTemp\": \"19,20\",\n" +
                "                    \"limitVal\": 0,\n" +
                "                    \"gunOutCont\": \"1,1\",\n" +
                "                    \"gunNo\": 1,\n" +
                "                    \"fuseAlarm\": 1,\n" +
                "                    \"elecLock\": 0,\n" +
                "                    \"dcMeterElect\": 4660.58,\n" +
                "                    \"currLimit\": 1,\n" +
                "                    \"connOutCont\": \"1,1\",\n" +
                "                    \"chgState\": 1,\n" +
                "                    \"batID\": \"888BBD9KA005\",\n" +
                "                    \"batFault\": \"-\",\n" +
                "                    \"batConn\": 1,\n" +
                "                    \"auxPowerVolt\": 2,\n" +
                "                    \"auxPowerState\": 1\n" +
                "                },\n" +
                "                {\n" +
                "                    \"workMode\": 1,\n" +
                "                    \"stopReason\": 0,\n" +
                "                    \"soc\": 100,\n" +
                "                    \"plugTemp\": \"19,20\",\n" +
                "                    \"limitVal\": 0,\n" +
                "                    \"gunOutCont\": \"1,1\",\n" +
                "                    \"gunNo\": 2,\n" +
                "                    \"fuseAlarm\": 1,\n" +
                "                    \"elecLock\": 0,\n" +
                "                    \"dcMeterElect\": 4570.82,\n" +
                "                    \"currLimit\": 1,\n" +
                "                    \"connOutCont\": \"1,1\",\n" +
                "                    \"chgState\": 1,\n" +
                "                    \"batID\": \"888BBD9KA005\",\n" +
                "                    \"batFault\": \"-\",\n" +
                "                    \"batConn\": 1,\n" +
                "                    \"auxPowerVolt\": 2,\n" +
                "                    \"auxPowerState\": 1\n" +
                "                }\n" +
                "            ],\n" +
                "            \"emergStop\": 1,\n" +
                "            \"door\": 1,\n" +
                "            \"comm\": 1,\n" +
                "            \"chgSwitch\": 0,\n" +
                "            \"chgState\": 2,\n" +
                "            \"chgRunMode\": 1,\n" +
                "            \"chgID\": \"9990990001000002\",\n" +
                "            \"chgFault\": \"-\",\n" +
                "            \"cabinetNo\": 2,\n" +
                "            \"batState\": 1,\n" +
                "            \"batID\": \"888BBD9KA005\",\n" +
                "            \"batFault\": \"-\",\n" +
                "            \"batConn\": 1,\n" +
                "            \"acCont\": 1\n" +
                "        },\n" +
                "        {\n" +
                "            \"workMode\": 1,\n" +
                "            \"startType\": 1,\n" +
                "            \"soc\": 56,\n" +
                "            \"smokeAlarm\": 1,\n" +
                "            \"plugSameBat\": 2,\n" +
                "            \"moduleState\": \"2,2,2,2,2,2,2,2,2,2\",\n" +
                "            \"moduleNum\": 10,\n" +
                "            \"gunNum\": 2,\n" +
                "            \"gunList\": [\n" +
                "                {\n" +
                "                    \"workMode\": 1,\n" +
                "                    \"stopReason\": 52,\n" +
                "                    \"soc\": 100,\n" +
                "                    \"plugTemp\": \"65486,65486\",\n" +
                "                    \"limitVal\": 0,\n" +
                "                    \"gunOutCont\": \"1,1\",\n" +
                "                    \"gunNo\": 1,\n" +
                "                    \"fuseAlarm\": 1,\n" +
                "                    \"elecLock\": 0,\n" +
                "                    \"dcMeterElect\": 2536.33,\n" +
                "                    \"currLimit\": 1,\n" +
                "                    \"connOutCont\": \"1,1\",\n" +
                "                    \"chgState\": 1,\n" +
                "                    \"batID\": \"777370340293\",\n" +
                "                    \"batFault\": \"-\",\n" +
                "                    \"batConn\": 1,\n" +
                "                    \"auxPowerVolt\": 2,\n" +
                "                    \"auxPowerState\": 1\n" +
                "                },\n" +
                "                {\n" +
                "                    \"workMode\": 1,\n" +
                "                    \"stopReason\": 0,\n" +
                "                    \"soc\": 100,\n" +
                "                    \"plugTemp\": \"65486,65486\",\n" +
                "                    \"limitVal\": 0,\n" +
                "                    \"gunOutCont\": \"1,1\",\n" +
                "                    \"gunNo\": 2,\n" +
                "                    \"fuseAlarm\": 1,\n" +
                "                    \"elecLock\": 0,\n" +
                "                    \"dcMeterElect\": 2530.12,\n" +
                "                    \"currLimit\": 1,\n" +
                "                    \"connOutCont\": \"1,1\",\n" +
                "                    \"chgState\": 1,\n" +
                "                    \"batID\": \"777370340293\",\n" +
                "                    \"batFault\": \"-\",\n" +
                "                    \"batConn\": 1,\n" +
                "                    \"auxPowerVolt\": 2,\n" +
                "                    \"auxPowerState\": 1\n" +
                "                }\n" +
                "            ],\n" +
                "            \"emergStop\": 1,\n" +
                "            \"door\": 1,\n" +
                "            \"comm\": 1,\n" +
                "            \"chgSwitch\": 0,\n" +
                "            \"chgState\": 2,\n" +
                "            \"chgRunMode\": 1,\n" +
                "            \"chgID\": \"9990990001000003\",\n" +
                "            \"chgFault\": \"-\",\n" +
                "            \"cabinetNo\": 3,\n" +
                "            \"batState\": 1,\n" +
                "            \"batID\": \"777370340293\",\n" +
                "            \"batFault\": \"-\",\n" +
                "            \"batConn\": 1,\n" +
                "            \"acCont\": 1\n" +
                "        },\n" +
                "        {\n" +
                "            \"workMode\": 1,\n" +
                "            \"startType\": 1,\n" +
                "            \"soc\": 31,\n" +
                "            \"smokeAlarm\": 1,\n" +
                "            \"plugSameBat\": 2,\n" +
                "            \"moduleState\": \"2,2,2,2,2,2,2,2,2,2\",\n" +
                "            \"moduleNum\": 10,\n" +
                "            \"gunNum\": 2,\n" +
                "            \"gunList\": [\n" +
                "                {\n" +
                "                    \"workMode\": 1,\n" +
                "                    \"stopReason\": 52,\n" +
                "                    \"soc\": 100,\n" +
                "                    \"plugTemp\": \"65486,65486\",\n" +
                "                    \"limitVal\": 0,\n" +
                "                    \"gunOutCont\": \"1,1\",\n" +
                "                    \"gunNo\": 1,\n" +
                "                    \"fuseAlarm\": 1,\n" +
                "                    \"elecLock\": 0,\n" +
                "                    \"dcMeterElect\": 2877.56,\n" +
                "                    \"currLimit\": 1,\n" +
                "                    \"connOutCont\": \"1,1\",\n" +
                "                    \"chgState\": 1,\n" +
                "                    \"batID\": \"666455340283\",\n" +
                "                    \"batFault\": \"-\",\n" +
                "                    \"batConn\": 1,\n" +
                "                    \"auxPowerVolt\": 2,\n" +
                "                    \"auxPowerState\": 1\n" +
                "                },\n" +
                "                {\n" +
                "                    \"workMode\": 1,\n" +
                "                    \"stopReason\": 0,\n" +
                "                    \"soc\": 100,\n" +
                "                    \"plugTemp\": \"65486,65486\",\n" +
                "                    \"limitVal\": 0,\n" +
                "                    \"gunOutCont\": \"1,1\",\n" +
                "                    \"gunNo\": 2,\n" +
                "                    \"fuseAlarm\": 1,\n" +
                "                    \"elecLock\": 0,\n" +
                "                    \"dcMeterElect\": 2779.55,\n" +
                "                    \"currLimit\": 1,\n" +
                "                    \"connOutCont\": \"1,1\",\n" +
                "                    \"chgState\": 1,\n" +
                "                    \"batID\": \"666455340283\",\n" +
                "                    \"batFault\": \"-\",\n" +
                "                    \"batConn\": 1,\n" +
                "                    \"auxPowerVolt\": 2,\n" +
                "                    \"auxPowerState\": 1\n" +
                "                }\n" +
                "            ],\n" +
                "            \"emergStop\": 1,\n" +
                "            \"door\": 1,\n" +
                "            \"comm\": 1,\n" +
                "            \"chgSwitch\": 0,\n" +
                "            \"chgState\": 2,\n" +
                "            \"chgRunMode\": 1,\n" +
                "            \"chgID\": \"9990990001000004\",\n" +
                "            \"chgFault\": \"-\",\n" +
                "            \"cabinetNo\": 4,\n" +
                "            \"batState\": 1,\n" +
                "            \"batID\": \"666455340283\",\n" +
                "            \"batFault\": \"-\",\n" +
                "            \"batConn\": 1,\n" +
                "            \"acCont\": 1\n" +
                "        }\n" +
                "    ]\n" +
                "}";

        //电池箱实时状态
        String content2 = " {\n" +
                "    \"header\": {\n" +
                "        \"version\": \"V3.0.7\",\n" +
                "        \"timeStamp\": \"" + dateFormat.format(date) + "\",\n" +
                "        \"reason\": 2,\n" +
                "        \"index\": 2936,\n" +
                "        \"function\": \"batState\"\n" +
                "    },\n" +
                "    \"dataBody\": [\n" +
                "        {\n" +
                "            \"totalSwapElect\": 4954,\n" +
                "            \"totalRepaymentElect\": 726.5,\n" +
                "            \"totalGunElect\": 982.9,\n" +
                "            \"totalDischgElect\": 6663.5,\n" +
                "            \"totalChgElect\": 5983.6,\n" +
                "            \"soh\": 100,\n" +
                "            \"soc\": 100,\n" +
                "            \"ratedVolt\": 618.2,\n" +
                "            \"ratedElect\": 284.3,\n" +
                "            \"ratedCapacity\": 460,\n" +
                "            \"manufacturer\": 7,\n" +
                "            \"gunNo\": 0,\n" +
                "            \"coolingType\": 3,\n" +
                "            \"chgSwitch\": 0,\n" +
                "            \"cabinetNo\": 1,\n" +
                "            \"batType\": 3,\n" +
                "            \"batID\": \"999BBDADA007\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"totalSwapElect\": 4122.2,\n" +
                "            \"totalRepaymentElect\": 628.5,\n" +
                "            \"totalGunElect\": 1214.1,\n" +
                "            \"totalDischgElect\": 5964.8,\n" +
                "            \"totalChgElect\": 5313.7,\n" +
                "            \"soh\": 100,\n" +
                "            \"soc\": 89.7,\n" +
                "            \"ratedVolt\": 618.2,\n" +
                "            \"ratedElect\": 284.3,\n" +
                "            \"ratedCapacity\": 456,\n" +
                "            \"manufacturer\": 1,\n" +
                "            \"gunNo\": 0,\n" +
                "            \"coolingType\": 3,\n" +
                "            \"chgSwitch\": 0,\n" +
                "            \"cabinetNo\": 2,\n" +
                "            \"batType\": 3,\n" +
                "            \"batID\": \"888BBD9KA005\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"totalSwapElect\": 5837.9,\n" +
                "            \"totalRepaymentElect\": 1015.8,\n" +
                "            \"totalGunElect\": 2567.4,\n" +
                "            \"totalDischgElect\": 9439.9,\n" +
                "            \"totalChgElect\": 8540.4,\n" +
                "            \"soh\": 95.60000000000001,\n" +
                "            \"soc\": 56,\n" +
                "            \"ratedVolt\": 618.2,\n" +
                "            \"ratedElect\": 0,\n" +
                "            \"ratedCapacity\": 456,\n" +
                "            \"manufacturer\": 1,\n" +
                "            \"gunNo\": 0,\n" +
                "            \"coolingType\": 3,\n" +
                "            \"chgSwitch\": 0,\n" +
                "            \"cabinetNo\": 3,\n" +
                "            \"batType\": 3,\n" +
                "            \"batID\": \"777370340293\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"totalSwapElect\": 7169.9,\n" +
                "            \"totalRepaymentElect\": 1281,\n" +
                "            \"totalGunElect\": 208.4,\n" +
                "            \"totalDischgElect\": 8673.4,\n" +
                "            \"totalChgElect\": 7782.6,\n" +
                "            \"soh\": 31,\n" +
                "            \"soc\": 100,\n" +
                "            \"ratedVolt\": 618.2,\n" +
                "            \"ratedElect\": 0,\n" +
                "            \"ratedCapacity\": 456,\n" +
                "            \"manufacturer\": 1,\n" +
                "            \"gunNo\": 0,\n" +
                "            \"coolingType\": 3,\n" +
                "            \"chgSwitch\": 0,\n" +
                "            \"cabinetNo\": 4,\n" +
                "            \"batType\": 3,\n" +
                "            \"batID\": \"666455340283\"\n" +
                "        }\n" +
                "    ]\n" +
                "}";

        //充电过程实时状态
        String content3 = "{\n" +
                "    \"dataBody\": {\n" +
                "        \n" +
                "        \"chgList\": [\n" +
                "            {\n" +
                "                \"batMaxVoltNo\": 4,\n" +
                "                \"gunNo\": 1,\n" +
                "                \"soc\": 99,\n" +
                "                \"batMinTemp\": 39,\n" +
                "                \"voltDemand\": 700.8,\n" +
                "                \"remainderChgTime\": 6,\n" +
                "                \"currDemand\": 0,\n" +
                "                \"vin\": \"-\",\n" +
                "                \"startTime\": \"2024-10-22 18:04:33\",\n" +
                "                \"chgTime\": 3081,\n" +
                "                \"chgOutputVolt\": 650.5,\n" +
                "                \"plugTemp\": \"0,0\",\n" +
                "                \"chgID\": \"9990990001000001\",\n" +
                "                \"batMaxTemp\": 49,\n" +
                "                \"batMinVoltNo\": 0,\n" +
                "                \"chgOutputCurr\": 40.9,\n" +
                "                \"batID\": \"999BBDADA007\",\n" +
                "                \"batMinVolt\": 0,\n" +
                "                \"chgQty\": 188.57,\n" +
                "                \"batMaxVolt\": 3.7,\n" +
                "                \"cabinetNo\": 1,\n" +
                "                \"dcMeterElect\": 530481.17,\n" +
                "                \"chgMode\": 2,\n" +
                "                \"batMaxTempNo\": 3,\n" +
                "                \"batMinTempNo\": 7\n" +
                "            }\n" +
                "        ],\n" +
                "        \"chgNum\": 1\n" +
                "    },\n" +
                "    \"header\": {\n" +
                "        \"timeStamp\": \"" + dateFormat.format(date) + "\",\n" +
                "        \"reason\": 2,\n" +
                "        \"function\": \"chargingData\",\n" +
                "        \"index\": 35306,\n" +
                "        \"version\": \"V3.0.7\"\n" +
                "    }\n" +
                "}";
        MqttUtils.sendMQTT(env, pubTopic, content);
        MqttUtils.sendMQTT(env, pubTopic, content1);
        MqttUtils.sendMQTT(env, pubTopic, content2);
        MqttUtils.sendMQTT(env, pubTopic, content3);

    }
}
